#region Using

using System;
using System.IO;
using System.Web;
using System.Net;
using System.ComponentModel;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Xml;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using BlogEngine.Core.Web.Controls;

#endregion

using BlogEngine.Core;

namespace Controls
{
    /// <summary>
    /// Creates and displays a slideshow.
    /// </summary>
    [ToolboxData("<{0}:SlideShow runat=server></{0}:SlideShow>")]
    public class SlideShow : PhotoFlashBase
    {
        public SlideShow() :base()
        {
            MediaPlayer = "imagerotator.swf";
            this.Width = BlogSettings.Instance.SlideShowWidth;
            this.Height = BlogSettings.Instance.SlideShowHeight;
        }

        private string _AlbumSlug = string.Empty;

        [BindableAttribute(true)]
        [CategoryAttribute("Appearance")]
        public string AlbumSlug
        {
            get { return _AlbumSlug; }
            set { _AlbumSlug = value; }
        }

        protected override void Render(HtmlTextWriter writer)
        {
            if (!string.IsNullOrEmpty(AlbumSlug))
            {
                Album album = Album.GetBySlug(AlbumSlug);

                if (album != null)
                {
                    int maxSize = this.Width.Value < this.Height.Value ? (int)this.Width.Value : (int)this.Height.Value; 
                    
                    //set all of the standard properties
                    base.AddParam("wmode", "opaque");
                    base.AddVariable("file", Utils.ConvertToAbsoluteString(string.Format("{0}photo.axd?slideshow={1}&size={2}", Utils.RelativeWebRoot, album.Id, maxSize)));
                    base.AddVariable("shuffle", BlogSettings.Instance.SlideShowEnableShuffleMode.ToString().ToLowerInvariant());
                    base.AddVariable("linkfromdisplay", "false");
                    base.AddVariable("shownavigation", BlogSettings.Instance.SlideShowShowNavBar.ToString().ToLowerInvariant());
                    base.AddVariable("showicons", BlogSettings.Instance.SlideShowShowLoadIcon.ToString().ToLowerInvariant());
                    base.AddVariable("overstretch", BlogSettings.Instance.SlideShowStretchImage);
                    base.AddVariable("backcolor", "0x"+BlogSettings.Instance.SlideShowBackGroundColor);
                    base.AddVariable("frontcolor", "0x"+BlogSettings.Instance.SlideShowTextColor);
                    base.AddVariable("lightcolor", "0x"+BlogSettings.Instance.SlideShowRolloverColor);
                    base.AddVariable("rotatetime", BlogSettings.Instance.SlideShowDuration.ToString());
                    base.AddVariable("transition", BlogSettings.Instance.SlideShowTransitionEffect);

                    //write the containing div and the player controls
                    base.RenderScript(writer, this.ID);
                }
            }
        }
    }
}